/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.lestr.udm.core.util;

import java.io.InputStream;
import java.util.List;
import org.lestr.udm.core.api.IDataManager;
import org.lestr.udm.core.api.IDataType;

/**
 *
 * @author pibonnin
 */
public class TreeDataManager implements IDataManager {


    private ITree tree;


    public TreeDataManager(ITree tree) {

        this.tree = tree;

    }// END Constructor


    @Override
    public ISession openSession() {

        return new Session();
        
    }// END Method openSession


    public static interface ITree {

        ITreeSession openSession();

    }// END Interface ITree


    public static interface ITreeSession {


        void addNode(String nodeAddress);


        void removeNode(String nodeAddress);


        List<String> getChildrenAddresses(String nodeAddress);


        void setNodeDataTypes(String nodeAddress,
                              List<IDataType> types);


        List<IDataType> getNodeDataTypes(String nodeAddress);


        void setNodeDataValue(String nodeAddress,
                              InputStream value);


        InputStream getNodeDataValue(String nodeAddress);

        
        void commit();
        
        
        void close();
        

    }// END Interface ITreeSession

    
    private class Session implements ISession {


        private ITreeSession treeSession;
        
        
        public Session(){
            
            treeSession = tree.openSession();
            
        }// END Constructor
        
        
        @Override
        public void addData(String id) {
            
            treeSession.addNode(id);
            
        }// END Method addData


        @Override
        public void setDataTypes(String id,
                                 List<IDataType> types) {
            
            treeSession.setNodeDataTypes(id, types);
            
        }// END Method setDataTypes


        @Override
        public List<IDataType> getDataTypes(String id) {
            
            throw new UnsupportedOperationException("Not supported yet.");
            
        }// END Method getDataTypes


        @Override
        public void setDataValue(String id,
                                 InputStream value) {
            
            throw new UnsupportedOperationException("Not supported yet.");
            
        }// END Method setDataValue


        @Override
        public InputStream getDataValue(String id) {
            
            throw new UnsupportedOperationException("Not supported yet.");
            
        }// END Method getDataValue


        @Override
        public void commit() {
            
            treeSession.commit();
            
        }// END Method commit


        @Override
        public void close() {
            
            treeSession.close();
            
        }// END Method close
        
        
    }// FIN Classe Session
    
    
}// END Class TreeDataManager
